package cn.wgx.safetyhelmet.web;


import cn.wgx.safetyhelmet.config.OaConfig;
import cn.wgx.safetyhelmet.handler.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class HelloController {

    @Autowired
    private OaConfig oaConfig;

    @GetMapping("/")
    public String index2(ModelMap map){
        map.addAttribute("host","cn.wgx.niubi");
        return "index";
    }

    @RequestMapping("/login")
    public String login(ModelMap map){
        return "login";
    }

    @GetMapping("hello")
    public String hello(ModelMap map){
        map.addAttribute("host","hello wgx");
        return "hello";
    }

    @GetMapping("hello2")
    @ResponseBody
    public String index(){
        int randomInt = oaConfig.getRandomInt();
        String uuid = oaConfig.getRandomUUID();
        return "Hello SpringBoot! "  + oaConfig.getSysName() + "</br>" + randomInt + "</br>" + uuid;
    }


    @GetMapping("exception")
    @ResponseBody
    public String exception() throws BaseException {
        throw new BaseException();
    }

}
